//
//  main.m
//  05-循环遍历
//
//  Created by dllo on 16/7/8.
//  Copyright © 2016年 高雅馨. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Nurse.h"
int main(int argc, const char * argv[]) {
    /**
     *  1⃣️
     */
    NSArray *stringArr = @[@"🇨🇳台湾",@"🇨🇳日本", @"🇨🇳钓鱼岛", @"🇨🇳香港", @"🇨🇳澳门"];
    NSMutableArray *newStringArr = [NSMutableArray array];
    for (NSInteger i = stringArr.count - 1; i >= 0; i--) {
        [newStringArr addObject:stringArr[i]];
    }
    NSLog(@"%@", newStringArr);
    /**
     *  2⃣️
     */
    // 可变字典
    NSDictionary *dic =
    @{@"name" : @"李煜", @"age" : @32, @"hobby" : @"吟诗"};
    NSMutableDictionary *dicMut = [dic mutableCopy];
    NSArray *keyCount = dicMut.allKeys;
    for (int i = 0; i < [keyCount count]; i++) {
        [dicMut objectForKey:[keyCount objectAtIndex:i]];
        NSLog(@"%@", keyCount[i]);
    }
    for (NSString *key in dicMut) {
        NSLog(@"%@", [dicMut objectForKey:key]);
    }
    // 3⃣️ NSEnumerator枚举器依赖于集合类型(数组字典集合), 不能单独使用
    NSArray *arrayEnum = @[@"aa", @"bb", @"cc", @"dd"];
    NSEnumerator *enumErator  = [arrayEnum objectEnumerator];
    id value = nil;
    while (value = [enumErator nextObject]) {
        NSLog(@"%@", value);
    };
    // 倒序枚举
    NSEnumerator *enumErator1  =
    [arrayEnum reverseObjectEnumerator];
    id value1 = nil;
    while (value1 = [enumErator1 nextObject]) {
        NSLog(@"%@", value1);
    };
    // 枚举器遍历字典
    NSEnumerator *enumErator2  = [arrayEnum objectEnumerator];
    id value2 = nil;
    while (value2 = [enumErator2 nextObject]) {
        NSArray *keys = [dicMut allKeysForObject:value2];
        NSLog(@"%@%@", keys, value2);
    };
    
    // 集合枚举(无序性)
    NSSet *set = [NSSet setWithObjects:@"110", @"120", @"119", nil];
    NSEnumerator *setEnum = [set objectEnumerator];
    id setValue = nil;
    while (setValue = [setEnum nextObject]) {
        NSLog(@"%@", setValue);
    };
    NSString *newString = [[NSString alloc] init];
    for (NSString *str in stringArr) {
       newString =  [newString stringByAppendingString:str];
    }
    NSLog(@"%@", newString);
#pragma mark - 知识点2 数组排序
#pragma mark - 知识点2.1 排序描述符
    NSArray *sortArrTest1 =
    @[@"a", @"b", @"c", @"d"];
    NSMutableArray *sortArrMutTest1 =
    [sortArrTest1 mutableCopy];
    /* ††††††††††††††††††††††††††††††实例化一个排序描述符††††††††††††††††††††††††††††††††*/
    NSSortDescriptor *sortDescriptor =
    [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES];
    /* ††††††††††††††††††††††††††††††对不可变数组进行排序††††††††††††††††††††††††††††††††*/
    NSArray *arrResult1 =
    [sortArrMutTest1 sortedArrayUsingDescriptors:@[sortDescriptor]];
    NSLog(@"%@", arrResult1);
    /* †††††††††††††††††††††††††††††††对可变数组进行排序†††††††††††††††††††††††††††††††††*/
    [sortArrMutTest1 sortUsingDescriptors:@[sortDescriptor]];
    NSLog(@"%@", sortArrMutTest1);
#pragma mark - 小结
    /*
     * 使用排序描述符对不可遍数组和可变数组排序的区别
     * 1 方法是否有返回值
     * 2 注意方法名的区别!!
     不可变: sortedArrayUsingDescriptors  排序后需要生成新的数组
     可变: sortUsingDescriptors 排序直接可以在本身之上修改
     */
    Nurse *nurse1 = [Nurse nurseWithName:@"🙈" Age:18];
    Nurse *nurse2 = [Nurse nurseWithName:@"🙉" Age:17];
    Nurse *nurse3 = [Nurse nurseWithName:@"🙊" Age:19];
    NSArray *nurseArr = @[nurse1, nurse2, nurse3];
    NSMutableArray *nurseMulArr =
    [nurseArr mutableCopy];
    /* ††††††††††††††††††††††††††††††对不可变数组进行排序††††††††††††††††††††††††††††††††*/
    NSArray *nurseArrResult  = [nurseArr sortedArrayUsingSelector:@selector(sortByAge:)];
    for (Nurse *temp in nurseArrResult) {
        NSLog(@"名字: %@ -- 年龄:%ld", temp.name, (long)temp.age);
    }
    /* †††††††††††††††††††††††††††††††对可变数组进行排序†††††††††††††††††††††††††††††††††*/
    [nurseMulArr sortUsingSelector:@selector(sortByAge:)  ];
    for (Nurse *temp in nurseMulArr) {
        NSLog(@"名字: %@ -- 年龄:%ld", temp.name, (long)temp.age);
    }
    NSSortDescriptor *perSort = [[NSSortDescriptor alloc] initWithKey:@"age" ascending:YES];
    [nurseMulArr sortedArrayUsingDescriptors:@[perSort]];
    NSLog(@"排序 : %@", nurseMulArr);
#pragma mark - 知识点2.2 方法选择器
    NSArray *arraySeleTest1 =
    @[@"abc", @"acc", @"bbc", @"bdc"];
    NSMutableArray *arrayMutSeleTest2 =
    [arraySeleTest1 mutableCopy];
    // 2.2.1 选择系统的比较方法对数组进行排序
    /* ††††††††††††††††††††††††††††††对不可变数组进行排序††††††††††††††††††††††††††††††††*/
    NSArray *arrayMutSeleTest2Result =
    [arraySeleTest1 sortedArrayUsingSelector:@selector(compare:)];
    NSLog(@"%@", arrayMutSeleTest2Result);
    /* †††††††††††††††††††††††††††††††对可变数组进行排序†††††††††††††††††††††††††††††††††*/
    [arrayMutSeleTest2 sortUsingSelector:@selector(compare:)];
    NSLog(@"%@", arrayMutSeleTest2Result);
    /*∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆*/

    return 0;
}
